package helper.request.plan;

import java.sql.SQLException;
import java.util.ArrayList;

import server.dbconnector.DatabaseConnector;

import helper.request.RequestUndo;
import base.Plan;
import base.User;

public class DelPlanRequest implements PlanRequest,RequestUndo{
	private static final long serialVersionUID = 2725515304857798011L;
	private User currentuser;
	private ArrayList<Plan> planList;
	private Plan clonePlan;
	private Plan plan;
	
	public DelPlanRequest(User currentuser,Plan plan,ArrayList<Plan> planList){
		this.currentuser=currentuser;
		this.clonePlan=plan.clone();
		this.plan=plan;
		this.planList=planList;
	}
	@Override
	public Plan getPlan() {
		return clonePlan;
	}

	@Override
	public User getcurrentuser() {
		return currentuser;
	}

	@Override
	public int getcurrentuserid() {
		return currentuser.getid();
	}
	@Override
	public boolean execute() {
		try{
			planList.remove(plan);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	@Override
	public boolean de_execute() {
		try{
			planList.add(plan);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	@Override
	public void process(DatabaseConnector dc)throws SQLException{
		dc.commit("delete from plan where id="+this.plan.getid());
		
	}
	public String toString(){
		return "删除了计划《"+plan.gettitle()+"》";
	}

}
